home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 May: Tool Chest / Developer CD Series May 1996 (Tool Chest) (Apple Computer) (1996).iso / Tool Chest / Developer Utilities / Installer 4.0.3 SDK / Script Examples / Preference Example / SetupFunction.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-15  |  7.8 KB  |  226 lines  |  [TEXT/MPS ]

  1.  
  2. #ifndef __Files__
  3. #include <Files.h>
  4. #endif
  5.  
  6. #ifndef __GestaltEqu__
  7. #include <GestaltEqu.h>
  8. #endif
  9.  
  10. #ifndef __Memory__
  11. #include <Memory.h>
  12. #endif
  13.  
  14. #ifndef __OSUtils__
  15. #include <OSUtils.h>
  16. #endif
  17.  
  18. #ifndef __Packages__
  19. #include <Packages.h>
  20. #endif
  21.  
  22. #ifndef __CallbackDispatcherHeader__
  23. #include "CallbackDispatcherHeader.h"
  24. #endif
  25.  
  26. #ifndef __ActionHandlerHeader__
  27. #include "ActionHandlerHeader.h"
  28. #endif
  29.  
  30. #ifndef __SetupFunctionHeader__
  31. #include "SetupFunctionHeader.h"
  32. #endif
  33.  
  34. #include <TextUtils.h>
  35.  
  36. /*
  37.     This Setup Function calls the System 7 PBCatSearch routine to search for the first
  38.     TeachText application found on the default volume.  If a copy of the application is
  39.     found, the folder's FSSpec is returned to the Installer to be considered for the 
  40.     suggested application folder.
  41.     
  42.     This function does nothing under pre-7.0 systems.
  43.     
  44.     You can use the accompanying routines to display information in the Installer Debugger 
  45.     to help you learn and debug your Setup Function.
  46.     
  47. */
  48.  
  49. void DisplayPreferenceInfo( EnvironmentSetupPBPtr        pSetupPBPtr, long pResultCode );
  50.  
  51. long SetupFunction( EnvironmentSetupPBPtr        pSetupPBPtr )
  52. {
  53.  
  54.     #define            kOptBufferSize    0x4000
  55.  
  56.     long            theResult = 0;
  57.     long            theSysVersionNum;
  58.     OSErr            theErr;
  59.     CInfoPBRec        theFirstSearchCriteria;
  60.     CInfoPBRec        theSecondSearchCriteria;
  61.     CSParam            theCatParamBlock;
  62.     FSSpec            theMatchedFSSpec;
  63.     long            theMaxNumOfMatches = 1;
  64.     char            *theOptionalBuffer=NewPtr(kOptBufferSize);
  65.     CInfoPBRec        theCatInfoParamBlock;
  66.     Str255            theTempStr255;
  67.     short            theByteCtr;
  68.  
  69.  
  70.     // If you want to select the default target volume and/or system disk set these fields
  71.  
  72.     Gestalt( 'sysv', &theSysVersionNum );
  73.     if( theSysVersionNum >= 0x00000700 ) {
  74.     
  75.         theCatParamBlock.ioCompletion        = NULL;
  76.         theCatParamBlock.ioNamePtr            = NULL;
  77.         theCatParamBlock.ioVRefNum            = pSetupPBPtr->fTargetFSSpec.vRefNum;
  78.         
  79.            theCatParamBlock.ioMatchPtr            = (FSSpecArrayPtr)&theMatchedFSSpec;        /* match array */
  80.         theCatParamBlock.ioReqMatchCount    = theMaxNumOfMatches;                        /* maximum allowable matches */
  81.         theCatParamBlock.ioSearchBits        = fsSBFlFndrInfo + fsSBFlAttrib;            /* search criteria selector */
  82.         theCatParamBlock.ioSearchInfo1        = &theFirstSearchCriteria;                    /* search values and range lower bounds */
  83.         theCatParamBlock.ioSearchInfo2        = &theSecondSearchCriteria;                    /* search values and range upper bounds */
  84.         theCatParamBlock.ioSearchTime        = 0;                                        /* length of time to run search */
  85.         theCatParamBlock.ioCatPosition.initialize    = 0;                                /* current position in the catalog */
  86.         theCatParamBlock.ioOptBuffer        = theOptionalBuffer;                        /* optional performance enhancement buffer */
  87.         theCatParamBlock.ioOptBufSize        = kOptBufferSize;                            /* size of buffer pointed to by ioOptBuffer */
  88.     
  89.         theFirstSearchCriteria.hFileInfo.ioFlFndrInfo.fdType        = 'APPL';
  90.         theFirstSearchCriteria.hFileInfo.ioFlFndrInfo.fdCreator        = 'ttxt';
  91.         theFirstSearchCriteria.hFileInfo.ioFlAttrib                    = 0x00;
  92.  
  93.         theSecondSearchCriteria.hFileInfo.ioFlFndrInfo.fdType        = 0xFFFFFFFF;        /*the type of the file*/
  94.         theSecondSearchCriteria.hFileInfo.ioFlFndrInfo.fdCreator    = 0xFFFFFFFF;        /*file's creator*/
  95.         theSecondSearchCriteria.hFileInfo.ioFlFndrInfo.fdFlags        = 0x0000;            /*flags ex. hasbundle,invisible,locked, etc.*/
  96.         theSecondSearchCriteria.hFileInfo.ioFlFndrInfo.fdLocation.h    = 0x0000;            /*file's location in folder*/
  97.         theSecondSearchCriteria.hFileInfo.ioFlFndrInfo.fdLocation.v    = 0x0000;            /*file's location in folder*/
  98.         theSecondSearchCriteria.hFileInfo.ioFlFndrInfo.fdFldr        = 0x0000;            /*folder containing file*/
  99.         theSecondSearchCriteria.hFileInfo.ioFlAttrib                = 0x10;
  100.         
  101.         theErr = PBCatSearchSync( &theCatParamBlock );
  102.     
  103.         if( theErr == noErr && theCatParamBlock.ioActMatchCount >= 1 ) {
  104.             
  105.             theCatInfoParamBlock.dirInfo.ioNamePtr         = &theTempStr255;
  106.             theCatInfoParamBlock.dirInfo.ioVRefNum         = theMatchedFSSpec.vRefNum;
  107.             theCatInfoParamBlock.dirInfo.ioFDirIndex     = -1;
  108.             theCatInfoParamBlock.dirInfo.ioDrDirID         = theMatchedFSSpec.parID;
  109.             theErr = PBGetCatInfoSync( &theCatInfoParamBlock );
  110.  
  111.             if( theErr == noErr ) {
  112.                 pSetupPBPtr->fTargetFSSpec.vRefNum    = theCatInfoParamBlock.dirInfo.ioVRefNum;
  113.                 pSetupPBPtr->fTargetFSSpec.parID    = theCatInfoParamBlock.dirInfo.ioDrParID;
  114.                 
  115.                 for( theByteCtr = 0; theByteCtr <= theCatInfoParamBlock.dirInfo.ioNamePtr[0]; theByteCtr++ )
  116.                     pSetupPBPtr->fTargetFSSpec.name[theByteCtr]    = theCatInfoParamBlock.dirInfo.ioNamePtr[theByteCtr];
  117.             }
  118.         DisposePtr(theOptionalBuffer);
  119.         }
  120.     
  121.     }
  122.     else {
  123.     
  124.         // Implement the pre-7.0 search code here
  125.     
  126.     }
  127.  
  128.     DisplayPreferenceInfo( pSetupPBPtr, theResult );
  129.     return theResult;
  130. }
  131.  
  132.  
  133. // -------------------------------------------------------------------------------------------------------------------------------------
  134. // The routines below are for displaying the contents of the parameter block passed to the Setup Function.
  135. // Call DisplayPreferenceInfo to write this information to the Installer Debugger.
  136.  
  137. void MakeFilePath( FSSpec* pFileFSSpec, Str255  pFilePath )
  138. {
  139.     
  140.     CInfoPBRec        cPBRec;
  141.     Str255            directoryName = "";
  142.     short            i;
  143.     OSErr            theErr;
  144.  
  145.     // Get the file name
  146.     for( i=0;i<=pFileFSSpec->name[0];i++)
  147.         pFilePath[i] = pFileFSSpec->name[i];
  148.  
  149.     cPBRec.hFileInfo.ioCompletion = NULL;
  150.     cPBRec.hFileInfo.ioNamePtr = directoryName;
  151.     cPBRec.hFileInfo.ioFDirIndex = -1;
  152.     cPBRec.hFileInfo.ioDirID = pFileFSSpec->parID;
  153.     cPBRec.hFileInfo.ioVRefNum = pFileFSSpec->vRefNum;
  154.     theErr = PBGetCatInfo( &cPBRec, 0 );
  155.  
  156.     // Preappend directoryName
  157.     BlockMove( pFilePath + 1, pFilePath + directoryName[0] + 2, pFilePath[0] );
  158.     for( i=1;i<=directoryName[0];i++)
  159.         pFilePath[i] = directoryName[i];
  160.     pFilePath[i] = ':';
  161.     pFilePath[0] += directoryName[0] + 1;
  162.  
  163.     while ( theErr == noErr && cPBRec.dirInfo.ioDrParID != 1 && pFilePath[0] + directoryName[0] + 1 < 255 ) {
  164.  
  165.     // Preappend directoryName
  166.         cPBRec.hFileInfo.ioDirID = cPBRec.dirInfo.ioDrParID;
  167.         cPBRec.hFileInfo.ioFDirIndex = -1;
  168.         theErr = PBGetCatInfo( &cPBRec, 0 );
  169.  
  170.         if( theErr == noErr ) {
  171.             // Preappend directoryName
  172.             BlockMove( pFilePath + 1, pFilePath + directoryName[0] + 2, pFilePath[0] );
  173.             for( i=1;i<=directoryName[0];i++)
  174.                 pFilePath[i] = directoryName[i];
  175.             pFilePath[i] = ':';
  176.             pFilePath[0] += directoryName[0] + 1;
  177.         }
  178.     }
  179.  
  180. }
  181.  
  182. void PrintLine( ProcPtr pCallBackProcPtr, Str255 pParam0, Str255 pParam1, Str255 pParam2, Str255 pParam3 )
  183. {
  184.     long    theResult;
  185.     RegisterScriptAction( pCallBackProcPtr, kDebuggingAction, kGenericDebugActID, pParam0, pParam1, pParam2, pParam3, &theResult );    
  186. }
  187.  
  188. void DisplayPreferenceInfo( EnvironmentSetupPBPtr    pSetupPBPtr, long pResultCode )
  189. {
  190.  
  191. StringPtr                    kBeginCallPart1                    = "\p=>========================== Begin Setup Function Call ====";
  192. StringPtr                    kBeginCallPart3                    = "\p==================================================";
  193.  
  194. StringPtr                    kEndCallPart1                    = "\p-<-------------------------- End Setup Function Call ------ ";
  195. StringPtr                    kEndCallPart3                    = "\p ----------------------------\n";
  196.  
  197. StringPtr                    kResultText                        = "\pResult Code: ";
  198.  
  199. StringPtr                    kTargetFolderPathText            = "\p    Target Folder Path:  ";
  200. StringPtr                    kSystemDiskText                    = "\p      System Disk Name:  ";
  201.  
  202. Str255                        tempNumStr;    
  203. Str255                        tempStr255;    
  204. FSSpec                        tempFSSpec;
  205.  
  206.     // -- Beginning line
  207.     PrintLine( pSetupPBPtr->fCallBackProcPtr, kBeginCallPart1, kBeginCallPart3, "\p", "\p" );
  208.  
  209.     // -- Target Folder Path
  210.     MakeFilePath( &(pSetupPBPtr->fTargetFSSpec), tempStr255 );
  211.     PrintLine( pSetupPBPtr->fCallBackProcPtr, kTargetFolderPathText, tempStr255, "\p", "\p" );
  212.  
  213.     // —— System Disks Name
  214.     tempFSSpec.name[0] = 0;
  215.     tempFSSpec.parID = 2;
  216.     tempFSSpec.vRefNum = pSetupPBPtr->fSystemVRefNum;
  217.     MakeFilePath( &tempFSSpec, tempStr255 );
  218.     PrintLine( pSetupPBPtr->fCallBackProcPtr, kSystemDiskText, tempStr255, "\p", "\p" );
  219.  
  220.     // -- Ending line
  221.     NumToString( pResultCode, tempNumStr );
  222.     PrintLine( pSetupPBPtr->fCallBackProcPtr, kEndCallPart1, kResultText, tempNumStr, kEndCallPart3 );
  223. }
  224.  
  225. #include "ActionHandlerCBGlue.c"
  226.